from django.db import models

# Create your models here.

from django.db import models

from records.models import Record
from utils.base_models import BaseModel


class Project(BaseModel):
    name = models.CharField(verbose_name='项目名称', help_text='项目名称', unique=True, max_length=50)
    leader = models.CharField(verbose_name='项目负责人', help_text='项目负责人', default='', max_length=50)

    class Meta:
        db_table = 'tb_project'
        verbose_name = 'project'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

    def info(self):
        return [
            {'name': '执行环境', 'value': self.environments.filter(is_deleted=False).count()},
            {'name': '测试场景', 'value': self.test_scenes.filter(is_deleted=False).count()},
            {'name': '测试计划', 'value': self.test_plans.filter(is_deleted=False).count()},
            {'name': '接口数量', 'value': self.interfaces.filter(is_deleted=False).count()},
            {'name': '定时任务', 'value': 0},  # TODO 定时任务还没有开发
            {'name': '执行记录', 'value': Record.objects.filter(plan__project=self, plan__is_deleted=False).count()}
        ]

    def bugs(self):
        return [
            {
                "name": "未处理bug",
                "value": self.bug_set.filter(status='未处理').count()
            },
            {
                "name": "处理中bug",
                "value": self.bug_set.filter(status='处理中').count()
            },
            {
                "name": "处理完bug",
                "value": self.bug_set.filter(status='处理完').count()
            },
            {
                "name": "无效bug",
                "value": self.bug_set.filter(status='无效bug').count()
            }
        ]
